<?php 
session_start();
$_SESSION['idEntreprise']=1;
//echo 'session: '.$_SESSION['idEntreprise'].'<br>';
require_once ('../include/prepend.php');
require_once('securimage.php');

	$img 		= new Securimage();
	$valid 		= $img->check($_POST['code']);

  if($valid == true) {
  	$delete = false;
	$entreprise	= new BDentreprise();
	$dirigent 	= new BDdirigents();
	$entrepriseHaveDirigent = new BDentreprise_have_dirigent();
	
	$dirigent->setId_civilite($_POST['idCivilite']);
	$dirigent->setNom($_POST['nom']);
	$dirigent->setPrenom($_POST['prenom']);
	$dirigent->setContact_principale(1);
	$dirigent->save();
	
	
	$entreprise->setNom_societe($_POST['libelleEntreprise']);
	$entreprise->setDate_inscription(date('Y-m-d h:i:s'));
	$entreprise->setAdresse($_POST['adresse'].$_POST['adresseSuite']);
	$entreprise->setId_ville($_POST['idVille']);
	$entreprise->setCode_postal($_POST['codePostal']);
	$entreprise->setTel($_POST['tel']);
	$entreprise->setFax($_POST['fax']);
	$entreprise->setId_gategori($_POST['idCategorie']);
	$entreprise->setId_sous_categori($_POST['idSousCategori']);
	$entreprise->setEmail($_POST['email']);
	$entreprise->setMdp($_POST['mdp']);
	$entreprise->save();
	
	if($entreprise->getId_entreprise() != 0 && $dirigent->getId_dirigent() != 0) {
		$entrepriseHaveDirigent->setId_dirigent($dirigent->getId_dirigent());
		$entrepriseHaveDirigent->setId_entreprise($entreprise->getId_entreprise());
		if($entrepriseHaveDirigent->save()){
			$_SESSION['idEntreprise'] = $entrepriseHaveDirigent->getId_entreprise();
			//session_register('idEntreprise',$entrepriseHaveDirigent->getId_entreprise());
			header('location:compte.php');
		}else{
			$delete = true;
		}
	}else{
		$delete = true;
	}
    
	if($delete == true) {
		$entreprise->delete();
		$dirigent->delete();
	}
  }
?>

<img src="http://www.mythumbshot.com/get?url=http://www.broad-it.com&size=xs" border="0" />

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>inscrition tunise entreprise</title>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script  type="application/javascript" language="javascript" src="../js/jquery.js"></script>
<script  type="application/javascript" language="javascript" src="../js/fns.js"></script>

<script type="application/javascript" language="javascript">
var url = 'ajax/ajaxmemebre.php';
function chargerSousCategori(id) {
	datta = 'partie=chargerSousCategori&idCategori='+id;
	AJAX(url,datta,'containerSousCategorie');
}
</script>

</head>
<body>

<table width="1024" border="1" cellpadding="0" cellspacing="0" align="center"><tr><td height="100">
header
</td></tr>
<tr>
  <td><a href="../index.php">Accueil</a> -> Créer un compte</strong></td></tr>
<tr><td>Pour créer un compte client sur Tunisie Entreprise , nous vous invitons à remplir ce formulaire.</td></tr>

<tr><td>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="200">connexion et menu</td>
<td>

<form name="inscription" method="post" action="inscription.php">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="4" style="color:red;"><?php echo $erreur; ?></td></tr>
<tr><td colspan="4"><h2>Créer un compte</h2></td></tr>
<tr><td colspan="4">
<table width="100%" cellpadding="1" cellspacing="1" class="border">
<tr>
<td width="120">Nom de l'organisme</td><td><input type="text" name="libelleEntreprise" value="<?php echo $_POST['libelleEntreprise']; ?>"  /></td><td width="120"></td><td></td>
</tr>
<tr>
<td>Civilité </td><td><?php echo select_one('idCivilite',BDcivilite::get(),'',$_POST['idCivilite'],'',false); ?></td><td></td><td></td>
</tr>
<tr>
<td>Nom responsable</td><td><input type="text" name="nom" value="<?php echo $_POST['nom']; ?>" /></td><td>Prénom</td> <td><input type="text" name="prenom" value="<?php echo $_POST['prenom']; ?>" /></td>
</tr>
<tr>
<td>Adresse  </td><td><input type="text" name="adresse" value="<?php echo $_POST['adresse']; ?>" /></td><td>Ville </td> <td><?php echo select_one('idVille',BDville::get(),'',$_POST['idVille']);?></td>
</tr>
<tr>
<td>Adresse (suite)  </td><td><input type="text" name="adresseSuite" value="<?php echo $_POST['adresseSuite']; ?>" /></td><td>Code postal </td> <td><input type="text" name="codePostal" value="<?php echo $_POST['codePostal']; ?>" /></td>
</tr>
<tr>
<td>Téléphone</td><td><input type="text" name="tel" value="<?php echo $_POST['tel']; ?>" /></td><td>Fax </td> <td><input type="text" name="fax" value="<?php echo $_POST['fax']; ?>" /></td>
</tr>
<tr>
<td>Catégorie</td>
<td><?php echo select_one('idCategorie',BDcategorie::get(),'',$_POST['idCategorie'],'onchange="chargerSousCategori(this.value);"'); ?></td>
<td>sous categorie</td> <td id="containerSousCategorie"><?php 
	$idCategori = (isset($_POST['idCategorie']))  ? $_POST['idCategorie'] : null;
	if($idCategori != null) {
		echo select_one('idSousCategori',BDsous_categori::get($idCategori),'',$_POST['idSousCategori']);
	}
?></td>
</tr>
</table>
</td></tr>
<tr><td colspan="4"><h2>Identifiants</h2></td></tr>
<tr><td>

<table width="100%" cellpadding="1" cellspacing="1" class="border">
<tr><td>Email</td><td><input type="text" name="email" value="<?php echo $_POST['email']; ?>" /></td><td>mot de passe </td> <td><input type="password" name="mdp" value="" /></td></tr>
</table>

</td></tr>

<tr>
<td colspan="4">
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<td width="20" align="right"><input type="checkbox" name="newsletter" value="1" checked="checked" /></td><td>Je souhaite recevoir la newsletter de Entreprise Tunisienne </td></tr>
</table>
</td></tr>
<tr><td>

<table width="100%" cellpadding="0" cellspacing="0">
<tr><td>code </td><td><input type="text" name="code" value="" /></td></tr>
<tr><td colspan="2"><img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"></td></tr>
</table>




<tr><td colspan="4" align="center"><input type="image" src="../images/btn-creerCompte.gif" /></td></tr>

</table>
</form>
</td>
<td width="120">publiciter</td></tr></table>
</td></tr>
<tr><td height="100"> pier de page</td></tr>
</table>
</body>
</html>